using Newtonsoft.Json;

namespace MyWebApi.Api.Utils
{
    // 序列化数据
    public class JsonHelper
    {
        public static string Serialize(dynamic obj){
            JsonSerializerSettings settings = new JsonSerializerSettings();
            // 避免循环引用
            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            // 序列化时间
            settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            // 序列化成小驼峰（首字母小写）
            settings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

            return JsonConvert.SerializeObject(obj,Formatting.Indented,settings);
        }
    }
    
}